package com.company.utils;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Auther Xue
 * @Date 2021/4/15
 * @Version 1.0
 * @Desc
 */
public class Regex {
    public static void main(String[] args) {
//
        Scanner scanner = new Scanner(System.in);
        String test = scanner.next();
//        verifyPassword(password);
//        verifyEmail(password);
//        verifyChinese(password);
//        verifyChinese("你好");
//        verifyChinese("你好");
//        String str = "350181199702281834";
//        verifyIdCard(str);
//          verifyURL(URL);
        verifyNeigtiveFloat(test);
    }

    //
    public static void verifyPassword(String password){
            Pattern pattern  = Pattern.compile(".{6,12}");
            Matcher matcher = pattern.matcher(password);
            if(!matcher.matches()){
                System.out.println("请输入6到12个字符");
                return;
            }
            pattern = pattern.compile(".*[A-Z]+");
            matcher = pattern.matcher(password);
            if(!matcher.lookingAt()){
                System.out.println("密码必须包含大写字母");
                return;
            }
            pattern = Pattern.compile(".*\\d+");
            matcher = pattern.matcher(password);
            if(!matcher.lookingAt()){
                System.out.println("密码必须包含数字");
                return;
            }
            else
                System.out.println("密码正确");
    }
    public static void verifyPhone(String phone){
        Pattern pattern = Pattern.compile("1[2-8]\\d{9}");
        Matcher matcher = pattern.matcher(phone);
        System.out.println(matcher.matches());
    }
    public static void verifyEmail(String email){
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$");
        Matcher matcher = pattern.matcher(email);
        if(!matcher.matches()){
            System.out.println("邮箱输入错误");
        }
        else{
            System.out.println("邮箱输入正确");
        }
    }
    public static void verifyChinese(String str){
        Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]");
        Matcher matcher = pattern.matcher(str);
        if(matcher.lookingAt()){
            System.out.println("含中文");
        }
        else{
            System.out.println("不含中文");
        }
    }
    public static void verifyIp(String str){
        Pattern pattern = Pattern.compile("(([1-9])|([1-9]\\d)|(1\\d\\d|(2[0-4]\\d|25[0-5]))\\.){3}(([1-9])|([1-9]\\d)|(1\\d\\d|(2[0-4]\\d|25[0-5])))");
        Matcher matcher = pattern.matcher(str);
        if(!matcher.lookingAt()){
            System.out.println("是IP");
        }
        else{
            System.out.println("不是IP");
        }
    }
    public static void verifyIdCard(String str){
        Pattern pattern = Pattern.compile("\\d{17}[\\d|X]|\\d{15}");
        Matcher matcher = pattern.matcher(str);
        if(!matcher.matches()){
            System.out.println("请输入15或18位数字或X身份证号");
            return;
        }
        pattern = Pattern.compile("[1-8]{2}\\d{4}(19\\d{2})|(20\\d{2})(0[1-9])|(1[0,2])\\d{5}(\\d|X)");
//日的判断


        matcher = pattern.matcher(str);
        if(!matcher.lookingAt()){
            System.out.println("请输入正确1900-2099内正确日期");
            return;
        }
        String yearMonth =  str.substring(6,12);
        int yearM = Integer.valueOf(yearMonth).intValue();
        getDay(yearM);
        System.out.println(yearMonth);
        int day = Integer.valueOf(str.substring(12,14)).intValue();
        if(day > getDay(yearM)) {
            System.out.println("请输入正确的day");
            return;
        }
        String nums = "7－9－10－5－8－4－2－1－6－3－7－9－10－5－8－4－2";
        List<String> list = Arrays.asList(nums.split("－"));
        Integer sum=0;
        for(int i=0;i<list.size();i++){
            int a =  Integer.valueOf(str.substring(i,i+1));
            int b =     Integer.valueOf(list.get(i));
            sum += a * b;
        }
        System.out.println(Integer.valueOf(str.substring(17)));
        System.out.println(sum%11);
        String verify = "1－0－X－9－8－7－6－5－4－3－2";
        List<String> list2 = Arrays.asList(verify.split("－"));
        System.out.println(list2.get(sum%11));
        if(!str.substring(17).equals(list2.get(sum%11))){
            System.out.println("校验码错误");
            return;
        }
        System.out.println("输入正确");
    }
    //输入年月的int数字
    public static int getDay(int date){
        int year = date/100;
        int month = date%100;
        if(month == 1||month ==3||month ==5||month ==7||month ==8||month ==10||month ==12)
            return 31;
        else if(month==2){
            return IsEven(year);
        }
        else
            return 30;
    }
    public static int IsEven(int year){
        if((year%4==0&&year%100!=0) || year%400 ==0){
            return 29;
        }
        return 28;
    }

    public static void verifyURL(String str){
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是URL");
        }
        else{
            System.out.println("不是URL");
        }
    }
    public static void verifyNeigtiveFloat(String str){
        Pattern pattern = Pattern.compile("-\\d+\\.?\\d*");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是负浮点数");
        }
        else{
            System.out.println("不是负浮点数");
        }
    }
    public static void verifyInterger(String str){
        Pattern pattern = Pattern.compile("-?\\d*");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是整形");
        }
        else{
            System.out.println("不是整形");
        }
    }
    public static void verifyQQ(String str){
        Pattern pattern = Pattern.compile("\\d{5-11}");
        Matcher matcher = pattern.matcher(str);
        if(!matcher.lookingAt()){
            System.out.println("是IP");
        }
        else{
            System.out.println("不是IP");
        }
    }
    public static void verifyPostalCode(String str){
        Pattern pattern = Pattern.compile("[1-8]{2}\\d{4}");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是邮编");
        }
        else{
            System.out.println("不是邮编");
        }
    }
    public static void verifyFormatDate(String str){
        Pattern pattern = Pattern.compile("");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是IP");
        }
        else{
            System.out.println("不是IP");
        }
    }
    public static void verifyIntergerPlus(String str){
        Pattern pattern = Pattern.compile("\\d{0,10}");
        Matcher matcher = pattern.matcher(str);
        if(!matcher.lookingAt()){
            System.out.println("是IP");
        }
        else{
            System.out.println("不是IP");
        }
    }
    public static void verifyPhoneNum(String str){
        Pattern pattern = Pattern.compile("\\d{3|8}");
        Matcher matcher = pattern.matcher(str);
        if(!matcher.lookingAt()){
            System.out.println("是电话号码");
        }
        else{
            System.out.println("不是电话号码");
        }
    }

    public static void verifyUserName(String str){
        Pattern pattern = Pattern.compile("\\w{6-18}");
        Matcher matcher = pattern.matcher(str);
        if(matcher.matches()){
            System.out.println("是用户名");
        }
        else{
            System.out.println("不是用户名");
        }
    }

}
